package com.ruoyi.system.controller;//package com.ruoyi.system.config;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.domain.OrderInfo;
import com.ruoyi.system.webSocket.ChatEndPoint;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author :
 * @date : 2024-10-23 11:50
 * @description :
 **/
@RestController
@RequestMapping("/info/driver")
@Slf4j
public class DriverController {
    @Resource
    private ChatEndPoint chatEndPoint;

    /**
     * 司机抢单
     * @param orderInfo
     * @param session
     * @return
     */
    @PostMapping("/robOrder")
    public AjaxResult login(@RequestBody OrderInfo orderInfo, HttpSession session) {
        log.info("司机抢单 orderInfo:{}",orderInfo);

        AjaxResult result = new AjaxResult();
        //抢订单,存入数据库

        //将抢单的司机Id存入到session中
        session.setAttribute("driverId",orderInfo.getDriverId());
        chatEndPoint.sendMessage("抢单完成，您的订单已被接受");
        log.info("抢单完成，您的订单已被接受");
        return result;
    }


}
